home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MYPROGS.ZIP
/
PUZZLE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-04-06
|
6KB
|
317 lines
program souris;
uses crt,graph,dos;
const max=16360;
maxp=540;
ECRAN=$A000;
lar=27;
hau=20;
niveaucomplex=80;
type tab= array [1..max] of byte;
tabp= array [0..24,1..maxp] of byte;
plateau= array [1..5,1..5] of byte;
tabnom= array[1..7] of string;
var x,y,bouton: integer;
nbbouton,status: integer;
fin :boolean;
image: tab;
f: file of tab;
largeimage:word;
hauteur_image:word;
place_ecran: word;
pimage: tabp;
p: plateau;
i:integer;
xp,yp: byte;
yc,xc: byte;
niveau: byte;
nom: tabnom;
FUNCTION TestMode(Mode:BYTE):BOOLEAN;
VAR REGS:REGISTERS;
BEGIN
WITH REGS DO
BEGIN
Ah:=$F;
Intr($10,REGS);
IF Al<>Mode THEN TestMode:=TRUE
ELSE TestMode:=FALSE;
END;
END;
PROCEDURE InitMode(Mode:BYTE);
VAR REGS:REGISTERS;
BEGIN
WITH REGS DO
BEGIN
Ah:=0;
Al:=Mode;
Intr($10,REGS);
IF TestMode(mode) THEN Write('Erreur Graphique Fatale !!!!');
END;
END;
procedure conversion;
var i: word;
BEGIN
for i:=1 to max do image[i]:=trunc(image[i]*0.063)+15;
END;
procedure AFFICHE_IMAGE;
var i,j: integer;
n,it: word;
BEGIN
n:=9;
i:=0;
it:=0;
repeat
j:=0;
repeat
mem[ECRAN:place_ecran+it+j]:=image[n];
mem[ECRAN:place_ecran+it+j+1]:=image[n];
mem[ECRAN:place_ecran+it+j+320]:=image[n];
mem[ECRAN:place_ecran+it+j+321]:=image[n];
inc(n);
inc(j);inc(j);
until j=largeimage*2;
inc(i);
it:=it+640;
until i=hauteur_image;
END;
procedure transfere;
var i,j: integer;
n,it,e: word;
BEGIN
for x:=0 to 23 do
BEGIN
n:=1;
i:=0;
it:=0;
e:=((x div 5))*640*hau+(x mod 5)*lar*2;
repeat
j:=0;
repeat
pimage[x,n]:=mem[ECRAN:place_ecran+it+j+e];
inc(n);
inc(j);inc(j);
until j>=lar*2;
inc(i);
it:=it+640;
until i>=hau;
END;
for i:=1 to maxp do pimage[24,i]:=0;
END;
procedure AFFICHE_petite_IMAGE( x,k : byte);
var i,j: integer;
n,it,e: word;
BEGIN
n:=1;
i:=0;
it:=0;
e:=(x div 5)*640*(hau-1)+(x mod 5)*lar*2;
repeat
j:=0;
repeat
mem[ECRAN:place_ecran+e+it+j]:=pimage[k,n];
mem[ECRAN:place_ecran+e+it+j+1]:=pimage[k,n];
mem[ECRAN:place_ecran+e+it+j+320]:=pimage[k,n];
mem[ECRAN:place_ecran+e+it+j+321]:=pimage[k,n];
inc(n);
inc(j);inc(j);
until j=lar*2;
inc(i);
it:=it+640;
until i=hau-1;
END;
procedure mousestatus(var status,nbbouton:integer);
var regs: REGISTERS;
BEGIN
with regs do
BEGIN
ax:=0;
intr($33,regs);
status:=ax;
nbbouton:=bx;
END;
END;
procedure montrepointeur;
var regs: REGISTERS;
BEGIN
with regs do
BEGIN
ax:=1;
intr($33,regs);
END;
END;
procedure cachepointeur;
var regs: REGISTERS;
BEGIN
with regs do
BEGIN
ax:=2;
intr($33,regs);
END;
END;
procedure posetbouton(var x,y,bouton:integer);
var regs: REGISTERS;
BEGIN
with regs do
BEGIN
ax:=3;
intr($33,regs);
x:=cx;
y:=dx;
bouton:=bx;
END;
END;
procedure lecture;
BEGIN
assign(f,nom[niveau]);
reset(f);
read(f,image);
close(f);
END;
procedure AFF_plateau;
var i,j:byte;
BEGIN
for i:=1 to 5 do
for j:=1 to 5 do
affiche_petite_image((i-1)*5+j-1,p[i,j]);
END;
procedure ECHANGE(var xp,yp,x,y:byte);
var tampon:byte;
BEGIN
tampon:=p[x,y];
p[x,y]:=p[xp,yp];
p[xp,yp]:=tampon;
xp:=x;
yp:=y;
END;
function GAGNE:boolean;
var i,j,n: byte;
test: boolean;
BEGIN
n:=0;
test:=true;
for i:=1 to 5 do
for j:=1 to 5 do
BEGIN
if p[i,j]<>n then test:=false;
inc(n);
END;
GAGNE:=test;
END;
procedure initplateau;
var i,j,n,a,xt,yt: byte;
y: word;
BEGIN
n:=0;
for i:=1 to 5 do
for j:=1 to 5 do
BEGIN
p[i,j]:=n;
inc(n);
END;
for y:=1 to niveaucomplex do
BEGIN
xt:=xp;
yt:=yp;
a:=random(4);
case a of
0: if xp-1>0 then BEGIN xt:=xt-1;echange(xp,yp,xt,yp);END;
1: if xp+1<6 then BEGIN xt:=xt+1;echange(xp,yp,xt,yp);END;
2: if yp-1>0 then BEGIN yt:=yt-1;echange(xp,yp,xp,yt);END;
3: if yp+1<6 then BEGIN yt:=yt+1;echange(xp,yp,xp,yt);END;
END;
END;
END;
function DEDANS(xi,xs,yi,ys:word):boolean;
BEGIN
DEDANS:=(x>xi) and (x<xs) and (y>yi) and (y<ys);
END;
procedure JEU_MOUSE;
var xt,yt: byte;
BEGIN
if DEDANS(place_ecran*2,(place_ecran+largeimage*2)*2,0,200)
then
BEGIN
xt:=(x-place_ecran*2) div (lar*2);
xt:=xt div 2;
inc(xt);
yt:=y div (hau*2);
inc(yt);
if ((yt=xp-1) and (xt=yp)) or
((yt=xp+1) and (xt=yp)) or
((yt=xp) and (xt=yp-1)) or
((yt=xp) and (xt=yp+1))
THEN
BEGIN
cachepointeur;
affiche_petite_image((xp-1)*5+yp-1,p[yt,xt]);
ECHANGE(xp,yp,yt,xt);
affiche_petite_image((xp-1)*5+yp-1,p[xp,yp]);
montrepointeur;
END;
END;
END;
BEGIN
writeln('Pour quitter appuyer sur le boutton de gauche et celui de droite');
writeln('Appuyer sur une touche ');
readkey;
randomize;
niveau:=1;
nom[1]:='dessin1.tif';
nom[2]:='dessin2.tif';
nom[3]:='dessin3.tif';
nom[4]:='dessin4.tif';
nom[5]:='dessin5.tif';
nom[6]:='dessin6.tif';
nom[7]:='dessin7.tif';
repeat
xp:=5;
yp:=5;
largeimage:=136;
hauteur_image:=100;
place_ecran:=(320-largeimage*2) div 2;
initmode($13);
lecture;
conversion;
affiche_image;
transfere;
clrscr;
initplateau;
aff_plateau;
mousestatus(status,nbbouton);
if status=0 then halt(1);
montrepointeur;
fin:=false;
repeat
posetbouton(x,y,bouton);
if bouton=3 then fin:=true;
if bouton=1 then jeu_mouse;
until (fin) or (gagne);
inc(niveau);
if not(fin) then BEGIN repeat
until keypressed;
END;
if niveau=7 then fin:=true;
until (fin);
cachepointeur;
status:=0;
initmode($03);
writeln(' A une prochaine');
END.